package com.tanguy.driver.ui.window

import android.content.Context
import android.view.View
import com.tanguy.driver.R
import com.tanguy.driver.base.BasePopupWindow
import com.tanguy.driver.utlis.extend.getSelectedItemString

import com.tanguy.user.utlis.extend.click

import com.weigan.loopview.LoopView
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/10/30 0030 11:09
 * 单个条目的选择器
 */
class TwoPickerViewPopupWindow(context: Context, private var stringOne: List<String>, private var stringTwo: List<String>, private val sureClick: (onePos: Int, oneMsg: String?,twoPos: Int, twoMsg: String?) -> Unit) : BasePopupWindow(context) {
    override fun setContentRes(): Int = R.layout.popup_picker_view
    private lateinit var mLoopOne: LoopView
    private lateinit var mLoopTwo: LoopView
    override fun setBackgroundAlpha(): Float = 0.7f
    override fun initView(view: View) {
        super.initView(view)
        view.apply {
            mLoopOne = find(R.id.lv_pop_one)
            mLoopTwo = find(R.id.lv_pop_two)
            mLoopTwo.visibility = View.VISIBLE
            click(R.id.tv_select_cancel) { this@TwoPickerViewPopupWindow.dismiss() }
            click(R.id.tv_select_confirm) {
                sureClick.invoke(mLoopOne.selectedItem, mLoopOne.getSelectedItemString(),mLoopTwo.selectedItem, mLoopTwo.getSelectedItemString())
                this@TwoPickerViewPopupWindow.dismiss()
            }
        }

    }

    override fun initEvent() {
        super.initEvent()
        initLoopOne()
        initLoopTwo()
    }

    private fun initLoopOne() {
        mLoopOne.setItems(stringOne)
        mLoopOne.setNotLoop()
        mLoopOne.setInitPosition(0)
        mLoopOne.setTextSize(20f)
    }

    private fun initLoopTwo() {
        mLoopTwo.setItems(stringTwo)
        mLoopTwo.setNotLoop()
        mLoopTwo.setInitPosition(0)
        mLoopTwo.setTextSize(20f)
    }


}